#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : logger.py
# @Author: Yang
# @Date  : 2021/1/26
# @Desc  :

import sys

class Logger(object):
    def __init__(self, filename="Default.log"):
        self.terminal = sys.stdout
        self.log = open(filename, "a")

    def write(self, message, num):
        data = message + str(num)
        self.log.write(data)
        self.log.write('\n')
        print(data)

    def write_tensor(self, q_eval, q_target):
        self.log.write('q_eval')
        self.log.write('\t')
        self.log.write('q_target')
        self.log.write('\n')
        for i in range(len(q_eval)):
            self.log.write(str(q_eval[i][0]))
            self.log.write('\t')
            self.log.write(str(q_target[i][0]))
            self.log.write('\n')

    def write_list(self, message, list):
        data = message + '['
        for i in list:
            data += str(i) + '\t'
        data += ']'
        self.log.write(data)
        self.log.write('\n') 
        print(data)

    def flush(self):
        pass

if __name__ == "__main__":
    # path
    from config.config import config
    cf = config()
    log_path = cf.getConfig('path', 'log_path')
    pic_path = cf.getConfig('path', 'picture_path')
    mod_path = cf.getConfig('path', 'model_path')

    # log
    log = Logger(log_path + 'run.log')
    log.write("Run.py从这又重新启动一次", '666')
    pseudorandom_log = Logger(log_path + 'pseudorandom.log')
    pseudorandom_log.write("Run.py从这又重新启动一次", '666')

    
